package org.ds.blog.exception;

import org.ds.blog.model.Response;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalException {
    @ExceptionHandler(CustomException.class)
    @ResponseBody
    public Response customException(CustomException e) {
        return Response.fail().code(e.getCode()).message(e.getMessage());
    }

    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public Response nullPointerException() {
        return Response.fail().code("44444").message("空指针异常,检查服务器");
    }
}
